package com.hcy.app.screen.relax

import androidx.room.Dao
import androidx.room.Entity
import androidx.room.Insert
import androidx.room.PrimaryKey
import androidx.room.Query
import androidx.room.Update

@Entity(tableName = "tb_file_info")
data class RelaxFileInfo(
    @PrimaryKey(autoGenerate = true)
    var id: Long = 0L,
    var name: String = "",
    var filePath : String ="", // 文件路径
    var fileType : String = "", // 文件类型
    var createdAt : Long = 0L, // 创建时间
    var isPrivate : Boolean = false, // 是否为私有文件
    var currentIndex: Long = 0L, // 当前下标，如果是书就是页数，如果是视频，就是秒
)

@Dao
interface RelaxFileInfoDao{
    @Query("select * from tb_file_info")
    fun findAll(): List<RelaxFileInfo>

    @Query("select * from tb_file_info where id = :id")
    suspend fun findById(id: Long): RelaxFileInfo?

    @Query("delete from tb_file_info where filePath = :filePath")
    suspend fun deleteByPath(filePath: String)

    @Query("delete from tb_file_info where id = :id")
    suspend fun deleteById(id: Long?)

    @Insert(RelaxFileInfo::class)
    suspend fun insert(s: RelaxFileInfo)

    @Update
    suspend fun update(s: RelaxFileInfo): Int

    @Query("update tb_file_info set currentIndex = :process where id = :id ")
    suspend fun updateProgress(id: Long?,process: Long): Int

    @Query("update tb_file_info set isPrivate = :isPrivate where id = :id ")
    suspend fun updatePrivate(id: Long?,isPrivate: Boolean): Int

}

